package cn.wolfcode.trip.base.util;

import cn.wolfcode.trip.base.domain.SystemInfo;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.mapper.SystemInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
@Component
public class SystemInfoUtils {

    private SystemInfoUtils(){}
    @Autowired
    private  SystemInfoMapper systemInfoMapper;
    /*
    * 发布通知
    * */
    public   void getReleaseString(Travel travel){
        //系统通知作者
        String title = null;//解码
        try {
            title = URLDecoder.decode(travel.getTitle(),"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String data = format.format(new Date());
        String content ="<div class=\"container systemMsg\">\n" +
                "                <dl class=\"itemList\">\n" +
                "                    <dd>\n" +
                "                        <p><font color=\"red\">32期男人帮通知：</font>恭喜你的游记<font color=\"blue\">"+title+"</font>。已被通过审核，成功发布。\t\t\n" +
                "\t\t祝您生活愉快。</p>\n" +
                "                        <p>"+data+"</p>\n" +
                "                    </dd>\n" +
                "               </dl>\n" +
                "   </div>";
        SystemInfo systemInfo = new SystemInfo();
        systemInfo.setUserId(travel.getAuthor().getId());
        systemInfo.setCreatTime(new Date());
        systemInfo.setState(false);
        systemInfo.setContent(content);
        System.out.println(systemInfoMapper);
        systemInfoMapper.insert(systemInfo);
    }
    /*
    * 每周之星
    * */
    public   void getWeekCommend(Travel travel){
        SystemInfo systemInfo = new SystemInfo();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String data = format.format(new Date());
        String content ="<div class=\"container systemMsg\">\n" +
                "                <dl class=\"itemList\">\n" +
                "                    <dd>\n" +
                "                        <p><font color=\"red\">32期男人帮通知：</font>恭喜你的游记<font color=\"blue\">"+travel.getTitle()+"</font>。已被评为每周之星，感谢您对我们的支持。\t\t\n" +
                "\t\t祝您生活愉快。</p>\n" +
                "                        <p>"+data+"</p>\n" +
                "                    </dd>\n" +
                "               </dl>\n" +
                "   </div>";
        systemInfo.setContent(content);
        systemInfo.setUserId(travel.getAuthor().getId());
        systemInfo.setCreatTime(new Date());
        systemInfo.setState(false);
        systemInfoMapper.insert(systemInfo);
    }
    /*
    * 每月之星
    * */
    public   void getMonthCommend(Travel travel){
        SystemInfo systemInfo = new SystemInfo();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String data = format.format(new Date());
        String content ="<div class=\"container systemMsg\">\n" +
                "                <dl class=\"itemList\">\n" +
                "                    <dd>\n" +
                "                        <p><font color=\"red\">32期男人帮通知：</font>恭喜你的游记<font color=\"blue\">"+travel.getTitle()+"</font>。已被评为每月之星，感谢您对我们的支持。\t\t\n" +
                "\t\t祝您生活愉快。</p>\n" +
                "                        <p>"+data+"</p>\n" +
                "                    </dd>\n" +
                "               </dl>\n" +
                "   </div>";
        systemInfo.setContent(content);
        systemInfo.setUserId(travel.getAuthor().getId());
        systemInfo.setCreatTime(new Date());
        systemInfo.setState(false);
        systemInfoMapper.insert(systemInfo);
    }
    /*
    * 攻略之星
    * */
    public   void getWStrategyCommend(Travel travel){
        SystemInfo systemInfo = new SystemInfo();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String data = format.format(new Date());
        String content ="<div class=\"container systemMsg\">\n" +
                "                <dl class=\"itemList\">\n" +
                "                    <dd>\n" +
                "                        <p><font color=\"red\">32期男人帮通知：</font>恭喜你的游记<font color=\"blue\">"+travel.getTitle()+"</font>。已被评为攻略之星，感谢您对我们的支持。\t\t\n" +
                "\t\t祝您生活愉快。</p>\n" +
                "                        <p>"+data+"</p>\n" +
                "                    </dd>\n" +
                "               </dl>\n" +
                "   </div>";
        systemInfo.setContent(content);
        systemInfo.setUserId(travel.getAuthor().getId());
        systemInfo.setCreatTime(new Date());
        systemInfo.setState(false);
        systemInfoMapper.insert(systemInfo);
    }
}
